﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ScoringClient.ViewModels;
using System.Windows.Media.Animation;
using ScoringClient.Notification;

namespace ScoringClient.Views
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        private MainWindowViewModel viewModel = new MainWindowViewModel();
        public static Window MainWindowHander;

        public MainWindow()
        {
            MainWindowHander = this;
            this.DataContext = viewModel;
            InitializeComponent();

            NotificationManager.Instance.MoveOn += new NotifyEventHander(LoadControls);

            NotificationRequest loginRequest = NotificationManager.Instance.CreateRequest(NotificationAction.Login);
            NotificationManager.Instance.MoveOn(loginRequest);
        }

        private void LoadControls(NotificationRequest request)
        {
            IWindow windowHander = null;
            switch (request.Action)
            {
                case NotificationAction.Login:
                    windowHander = new Login();
                    break;
                case NotificationAction.ScoringCatalog:
                    windowHander = new ScoringCatalog();
                    break;
            }

            if (windowHander != null)
            {
                viewModel.Title = windowHander.ViewModel.WindowTitle;
                viewModel.Height = windowHander.ViewModel.WindowHeight;
                viewModel.Width = windowHander.ViewModel.WindowWidth;

                this.bodyControl.Content = windowHander;
                this.Height = viewModel.Height;
                this.Width = viewModel.Width;
            }
        }
    }
}
